'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const db = uniCloud.database({})
	const shop = db.collection("db_user_web")
	//返回数据给客户端
	let dd;
	await shop.aggregate().match({
		uid: event.uid,
	}).lookup({
		from: 'db_shop',
		localField: 'item_id',
		foreignField: 'item_id',
		as: 'shop'
	}).end().then((res) => {
		dd = res.data
		for (let i = 0; i < dd.length; i++) {
			if (dd[i]["shop"][0]["item_img"]) {
				dd[i]["img"] = dd[i]["shop"][0]["item_img"]
				dd[i]["title"] = dd[i]["shop"][0]["item_title"]
				dd[i]["content"] = dd[i]["shop"][0]["item_content"]
				dd[i]["price"] = dd[i]["shop"][0]["item_price"]
				dd[i]["id"] = dd[i]["shop"][0]["_id"]
				dd[i]["item_shops"] = dd[i]["shop"][0]["item_shops"]
				dd[i]["flat"] = false
				dd[i]["num"] = dd[i]["shop"][0]["num"]
			}


			// console.log(dd[i]["shop"][0].item_img)

		}
	})
	return dd.reverse()
};